export function withStore(options) {
  return  {
    props: ['fetch'],
    data() {
      return {
        data: [],
        loading: true,
        error: false,
      }
    },
    created() {
      this.load()
    },
    methods: {
      load() {
        this.loading = true
        this.error = false
        
        this.fetch().then(data => {
          this.data = data
          this.loading = false
        }).catch(error => {
          this.error = true
          this.loading = false
        })
      }
    },
    template: options.template,
  }
}
